//
//  CheckSafetyForIpadVC.m
//  RoadMaintain
//
//  Created by 岳学坤 on 2017/3/17.
//  Copyright © 2017年 岳学坤. All rights reserved.
//

#import "CheckSafetyForIpadVC.h"
#import "SearchForDiseaseListIPadCell.h"
#import "PutNormolForIPadCell.h"
#import "SearchForDiseaseAddPicsForIPadCell.h"
#import "SearchForDiseaseDetailForIPadCell.h"
#import "MoreBtnForIpadCell.h"
#define ListCellID @"cellid1"
#define PutCellID  @"cellid2"
#define PicCellID  @"cellid3"
#define DetailCellID @"cellid4"
#define MoreBtnCellID @"cellid5"
@interface CheckSafetyForIpadVC ()<DetailForIPadCellDelegate,MoreBtnForIPadCellDelegate,PicsForIPadDelegate,UIAlertViewDelegate>
{
    NSInteger _selectedIndex;//选中查看第几个
    NSString * _status;//0 保存  1  上报
    
}
@property (nonatomic) NSInteger state;//0未上报  1已上报
@property (nonatomic,strong) NSString *codeId;
@property (nonatomic,strong) NSArray *titleArray;
@property (nonatomic,strong) NSArray *contentArray;
@property (nonatomic,strong) UIView *rightFooterView;
@property (nonatomic,strong) NSMutableArray *safeListArray;
@property (nonatomic,strong) NSDictionary *dic;//获取的需要展示的ID字典

@property (nonatomic,strong) NSMutableArray *routeArray;
@property (nonatomic,strong) NSString *routeId;
@property (nonatomic,strong) NSString *routeName;
@property (nonatomic,strong) NSString *elseThing;
@property (nonatomic,strong) NSString *idea;
@property (nonatomic,strong) NSMutableArray *imgArray;
@property (nonatomic,strong) NSString *detail;
@property (nonatomic,strong) NSString *checkTime;
@property (nonatomic,strong) NSString *checkerName;
@property (nonatomic,strong) NSString *checkerId;
@property (nonatomic,strong) NSString *safetyUserName;
@property (nonatomic,strong) NSString *safetyUserId;
@property (nonatomic,strong) NSString *doInfo;

@property (nonatomic,strong) NSMutableArray * deleteArray;//删除的图片数组
@end

@implementation CheckSafetyForIpadVC

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    [self resetNav];
    [self setTableViewFooterView];
    [MBProgressHUD showHUDAddedTo:self.tableView animated:YES];
    [self setWebData];
}
#pragma mark - Property
- (NSArray *)titleArray{
    if (_titleArray==nil) {
        _titleArray = @[@"路线编码",@"通知单编码",@"其他情况",@"对出现安全隐患处理意见(必填)",@"施工项目内容(必填)",@"检查人",@"检查日期",@"安全管理员",@"安全员签字日期",@"巡查日期",@"现场安全措施照片",@"备注"];
    }
    return _titleArray;
}
- (NSArray *)contentArray{
    if (_contentArray==nil) {
        _contentArray = @[@"",@"",@"请描述其他情况",@"请填写您的处理意见",@"请填写具体施工内容",@"",@"",@"",@"",@"",@"",@"请填写备注内容"];
    }
    return _contentArray;
}
- (NSMutableArray *)deleteArray{
    if (_deleteArray == nil) {
        _deleteArray = [[NSMutableArray alloc]initWithCapacity:1];
    }
    return _deleteArray;
}
- (NSArray *)safeListArray{
    if (_safeListArray==nil) {
        _safeListArray = [[NSMutableArray alloc]initWithCapacity:1];
        [_safeListArray addObjectsFromArray:@[@"0",@"0",@"0",@"0",@"0",@"0"]];
    }
    return _safeListArray;
}
- (NSMutableArray *)imgArray{
    if (_imgArray==nil) {
        _imgArray = [[NSMutableArray alloc]initWithCapacity:1];
    }
    return _imgArray;
}
- (NSMutableArray *)routeArray{
    if (_routeArray == nil) {
        _routeArray = [[NSMutableArray alloc]initWithCapacity:1];
    }
    return _routeArray;
}
#pragma mark - UI
- (void)resetNav{
    self.leftTitle = @"首页";
    self.pullRefreshEnable = YES;
    self.pullLoadMoreEnable = YES;
    self.myTitle.text = @"安全检查";
    [self.tableView registerClass:[SearchForDiseaseListIPadCell class] forCellReuseIdentifier:ListCellID];
    [self.rightTableView registerClass:[PutNormolForIPadCell class] forCellReuseIdentifier:PutCellID];
    [self.rightTableView registerClass:[SearchForDiseaseAddPicsForIPadCell class] forCellReuseIdentifier:PicCellID];
    [self.rightTableView registerClass:[SearchForDiseaseDetailForIPadCell class] forCellReuseIdentifier:DetailCellID];
    [self.rightTableView registerClass:[MoreBtnForIpadCell class] forCellReuseIdentifier:MoreBtnCellID];
}
- (void)setTableViewFooterView{

    
    self.rightFooterView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.rightTableView.frame.size.width, 212*PadHeightRate)];
    self.rightFooterView.backgroundColor = Bai_Color;
    self.rightTableView.tableFooterView = self.rightFooterView;
    
    UIButton *saveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    saveBtn.layer.cornerRadius = 5;
    saveBtn.layer.masksToBounds = YES;
    saveBtn.layer.borderColor = [MAIN_Color CGColor];
    saveBtn.layer.borderWidth = 1;
    saveBtn.backgroundColor = Bai_Color;
    [saveBtn setTitleColor:MAIN_Color forState:UIControlStateNormal];
    [saveBtn setTitle:@"保存" forState:UIControlStateNormal];
    [saveBtn addTarget:self action:@selector(save) forControlEvents:UIControlEventTouchUpInside];
    saveBtn.titleLabel.font = [UIFont systemFontOfSize:17*PadZitiRate];
    [self.rightFooterView addSubview:saveBtn];
    [saveBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(-139*PadHeightRate);
        make.height.mas_equalTo(42*PadHeightRate);
        make.left.mas_equalTo(22*PadWidthRate);
        make.right.equalTo(self.rightFooterView.mas_centerX).offset(-15*PadWidthRate);
    }];
    
    
    UIButton *submit = [UIButton buttonWithType:UIButtonTypeCustom];
    submit.layer.cornerRadius = 5;
    submit.layer.masksToBounds = YES;
    submit.backgroundColor = MAIN_Color;
    [submit setTitleColor:Bai_Color forState:UIControlStateNormal];
    [submit setTitle:@"上报" forState:UIControlStateNormal];
    [submit addTarget:self action:@selector(submit) forControlEvents:UIControlEventTouchUpInside];
    submit.titleLabel.font = [UIFont systemFontOfSize:17*PadZitiRate];
    [self.rightFooterView addSubview:submit];
    [submit mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(-139*PadHeightRate);
        make.height.mas_equalTo(42*PadHeightRate);
        make.right.mas_equalTo(-22*PadWidthRate);
        make.left.equalTo(self.rightFooterView.mas_centerX).offset(15*PadWidthRate);
    }];
}
#pragma mark - UI Response

- (void)save{
    _status = @"0";
    [self putData];
}
- (void)submit{
    _status = @"1";
    [self putData];
}
- (void)putData{
    
    
    if ([self.routeId length]==0) {
        [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"路线编码不能为空。" animated:YES];
    }else if ([self.idea length]==0) {
        [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"对出现安全隐患处理意见不能为空。" animated:YES];
    }else if ([self.doInfo length]==0) {
        [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"施工项目内容不能为空。" animated:YES];
    }else{
        if ([_status integerValue]==1) {
            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"上报" message:@"确定上报此安全检查单吗?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
            [alert show];
        }else{
            [self endPutData];
        }
        
    }
    
}
- (void)endPutData{
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    NSMutableArray * addImgArray = [[NSMutableArray alloc]initWithCapacity:1];
    for (int i = 0; i<self.imgArray.count; i++) {
        if ([self.imgArray[i] isKindOfClass:[UIImage class]]) {
            [addImgArray addObject:self.imgArray[i]];
        }
    }
    
    [NetWorkTool putUpSafetyCheck:self.dic[@"securityCheckId"] isSignCorrect:self.safeListArray[0] isSaftycoat:self.safeListArray[1] ifSafetyProcess:self.safeListArray[2] isSafetyTraffic:self.safeListArray[3] isSafeGuard:self.safeListArray[4] isExistedSafetyman:self.safeListArray[5] otherContent:self.elseThing dealSuggestion:self.idea content:self.doInfo checkerUser:self.checkerId checkerDate:self.dic[@"checkerDate"] safetyManager:self.safetyUserId signDate:self.checkTime remark:self.detail routeId:self.routeId state:_status block:^(id data) {
        
        if (data) {
            if ([data[@"success"]integerValue]) {
                
                [NetWorkTool userHeadImg:addImgArray deleteArr:self.deleteArray billId:self.dic[@"securityCheckId"] billType:@"dmSecurityCheck" success:^(NSDictionary *responseObject) {
                    [MBProgressHUD hideAllHUDsForView:self.view animated:NO];

                    if ([_status integerValue]==0) {
                        [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"保存成功" animated:YES];
                    }else{
                        [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"上报成功" animated:YES];
                    }
                    
                    self.page = 1;
                    [self setWebData];
                } failure:^(NSError *error) {
                   [MBProgressHUD hideAllHUDsForView:self.view animated:NO];

                    [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"网络错误，操作失败。" animated:YES];
                } uploadProgressBlock:^(float uploadPercent, long long totalBytesWritten, long long totalBytesExpectedToWrite) {
                    
                }];
                
            }else{
                 [MBProgressHUD hideAllHUDsForView:self.view animated:NO];
                if ([data[@"message"] isEqualToString:@"请求需要进行验证,请重新传入Token"]) {
                    [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"账号被其他设备登录，请重新登录" animated:YES];
                    [self performSelector:@selector(gotoLogin) withObject:nil afterDelay:1];
                }else{
                    [MBProgressHUD showTextHUDAddedTo:self.view Msg:data[@"message"] animated:YES];
                }
            }
        }else{
           [MBProgressHUD hideAllHUDsForView:self.view animated:NO];
            [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"网络错误，操作失败。" animated:YES];
        }
    }];
    
}

- (void)normolState:(NSInteger)state{
    if (state) {
        self.rightTableView.tableFooterView.hidden = YES;
    }else{
        self.rightTableView.tableFooterView.hidden = NO;
    }
    self.myCodeTitle.text = self.dataArray[_selectedIndex][@"billNo"];
}
#pragma mark - Data handle
- (void)setWebData{
    [NetWorkTool safetyCheckWithPage:self.page pageSize:10 block:^(id data) {
        [self performSelector:@selector(MJRefreshStop) withObject:nil afterDelay:1];
        [MBProgressHUD hideAllHUDsForView:self.tableView animated:NO];
        if (data) {
            if ([data[@"success"] integerValue]) {
                if (self.page == 1) {
                    self.tableView.contentOffset = CGPointMake(0, 0);
                    [self.dataArray removeAllObjects];
                    _selectedIndex = 0;
                    if ([data[@"data"][@"items"]isKindOfClass:[NSArray class]]) {
                        [self.dataArray addObjectsFromArray:data[@"data"][@"items"]];
                    }
                }else{
                    if ([data[@"data"][@"items"]isKindOfClass:[NSArray class]]) {
                        [self.dataArray addObjectsFromArray:data[@"data"][@"items"]];
                    }
                }
                if ([data[@"data"][@"items"]isKindOfClass:[NSArray class]]) {
                    if ([data[@"data"][@"items"] count]<10&&(self.dataArray.count!=0)) {
                        [self.tableView.mj_footer endRefreshingWithNoMoreData];
                    }
                }
                if (self.dataArray.count == 0) {
                    self.noDataView.hidden = NO;
                    self.rightTableView.tableFooterView.hidden = YES;
                }else{
                    self.noDataView.hidden = YES;
                    self.codeId = self.dataArray[0][@"securityCheckId"];
                    NSString *str = [NSString stringWithFormat:@"%@",self.dataArray[0][@"vcBooleanCode"]];
                    if ([str integerValue]) {
                        self.state = 1;
                    }else{
                        self.state = 0;
                    }
                    [self setWebDataDetail];
                }
                [self normolState:self.state];
                [self.tableView reloadData];
                self.rightTableView.contentOffset = CGPointMake(0, 0);
            }else{
                if ([data[@"message"] isEqualToString:@"请求需要进行验证,请重新传入Token"]) {
                    [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"账号被其他设备登录，请重新登录" animated:YES];
                    [self performSelector:@selector(gotoLogin) withObject:nil afterDelay:1];
                }else{
                    [MBProgressHUD showTextHUDAddedTo:self.view Msg:data[@"message"] animated:YES];
                }
            }
            
        }else{
            [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"网络错误，请检查网络后重试。" animated:YES
             ];
        }
    }];
}
- (void)setWebDataDetail{
    self.rightTableView.contentOffset = CGPointMake(0, 0);
    [self.rightTableView reloadData];
    [MBProgressHUD showHUDAddedTo:self.rightTableView animated:YES];
    [NetWorkTool safetyCheckDetailWithID:self.codeId block:^(id data) {
   [MBProgressHUD hideAllHUDsForView:self.rightTableView animated:NO];
        if (data) {
            if ([data[@"success"] integerValue]) {
                self.dic = data[@"data"][@"DmSecurityCheckList"];
                self.routeName = self.dic[@"routeCode"];
                self.routeId = self.dic[@"routeId"];
                [self.routeArray removeAllObjects];
                [self.routeArray addObjectsFromArray:data[@"data"][@"BdRouteList"]];
                
                self.detail = self.dic[@"remark"];
                self.elseThing = self.dic[@"otherContent"];
                self.idea = self.dic[@"dealSuggestion"];
                self.checkerName = self.dic[@"checkerUserName"];
                self.checkerId = self.dic[@"checkerUser"];
                self.safetyUserId = self.dic[@"safetyManager"];
                self.safetyUserName = self.dic[@"safetyManagerName"];
                self.checkTime = self.dic[@"signDate"];
                self.doInfo = self.dic[@"content"];
                
                [self.imgArray removeAllObjects];
                if ([self.dic[@"filePath"] length]==0) {
                    
                }else{
                    [self.imgArray addObjectsFromArray: [self.dic[@"filePath"] componentsSeparatedByString:@","]];
                }
                                
                [self.safeListArray replaceObjectAtIndex:0 withObject:self.dic[@"isSignCorrect"]];
                [self.safeListArray replaceObjectAtIndex:1 withObject:self.dic[@"isSaftycoat"]];
                [self.safeListArray replaceObjectAtIndex:2 withObject:self.dic[@"ifSafetyProcess"]];
                [self.safeListArray replaceObjectAtIndex:3 withObject:self.dic[@"isSafetyTraffic"]];
                [self.safeListArray replaceObjectAtIndex:4 withObject:self.dic[@"isSafeGuard"]];
                [self.safeListArray replaceObjectAtIndex:5 withObject:self.dic[@"isExistedSafetyman"]];
                
                [self.rightTableView reloadData];
            }else{
                if ([data[@"message"] isEqualToString:@"请求需要进行验证,请重新传入Token"]) {
                    [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"账号被其他设备登录，请重新登录" animated:YES];
                    [self performSelector:@selector(gotoLogin) withObject:nil afterDelay:1];
                }else{
                    [MBProgressHUD showTextHUDAddedTo:self.view Msg:data[@"message"] animated:YES];
                }
            }
        }else{
                [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"网络错误，请检查网络后重试。" animated:YES];
        }
    }];
}
- (void)gotoLogin{
    [PublicMethod noTokenToLoginWithNav:self.navigationController];
}
#pragma mark - Delegate
- (void)detailForIPadCellWithString:(NSString *)str indexPath:(NSIndexPath *)indexPath{
    if (indexPath.row==2) {
        self.elseThing = str;
    }else if (indexPath.row==3){
        self.idea = str;
    }else if (indexPath.row==4){
        self.doInfo = str;
    }else{
        self.detail = str;
    }
}

- (void)picsForIPadWithImgArray:(NSMutableArray *)arr AndDeleteArray:(NSMutableArray *)deleteArray{
    [self.imgArray removeAllObjects];
    [self.imgArray addObjectsFromArray:arr];
    [self.deleteArray removeAllObjects];
    [self.deleteArray addObjectsFromArray:deleteArray];
}
- (void)moreBtnForIPadCellWithArray:(NSMutableArray *)arr{
    [self.safeListArray removeAllObjects];
    [self.safeListArray addObjectsFromArray:arr];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if ([tableView isEqual:self.tableView]) {
        return self.dataArray.count;
    }else{
        if ([self.imgArray count]==0&&self.state==1) {
            return 11;
        }else{
            return 12;
        }
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([tableView isEqual:self.tableView]) {
        SearchForDiseaseListIPadCell *cell = (SearchForDiseaseListIPadCell *)[self tableView:self.tableView cellForRowAtIndexPath:indexPath];
        return cell.cellHeight;
    }else{
        if (indexPath.row==0) {
            return 68*PadHeightRate;
        }else if(indexPath.row == 1){
            return 138*PadHeightRate;
        }else if(indexPath.row==2||indexPath.row==3||indexPath.row==4){
            return 100*PadHeightRate;
        }else if(indexPath.row == 10){
            return 146*PadHeightRate;
        }else if(indexPath.row == 11){
            return 152*PadHeightRate;
        }
        else{
            return 50*PadHeightRate;
        }
    }
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([tableView isEqual:self.tableView]) {
        SearchForDiseaseListIPadCell *cell = [tableView dequeueReusableCellWithIdentifier:ListCellID];
        if (_selectedIndex == indexPath.row) {
            cell.contentView.backgroundColor = Bai_Color;
            
            cell.contentView.layer.borderWidth = 0;
            cell.blueLine.hidden = NO;
        }else{
            cell.contentView.backgroundColor = [PublicMethod colorWithHexString:@"#f4f4f4" andAlpha:1];
            cell.contentView.layer.borderColor = [Line_Color CGColor];
            cell.contentView.layer.borderWidth = 1;
            cell.blueLine.hidden = YES;
        }
        [cell safetyCheckAddValue:self.dataArray[indexPath.row]];
        return cell;
    }else{
        if (indexPath.row == 1) {
            MoreBtnForIpadCell *cell = [tableView dequeueReusableCellWithIdentifier:MoreBtnCellID];
            cell.titleLab.text = self.titleArray[indexPath.row];
            cell.contentLab.text = self.dic[@"maintentanceNoticeNo"];
            cell.delegate = self;
            cell.state = self.state;
            [cell addValue:self.safeListArray];
            return cell;
        }else if (indexPath.row == 10) {
            SearchForDiseaseDetailForIPadCell *cell = [tableView dequeueReusableCellWithIdentifier:DetailCellID];
            if ([self.imgArray count]==0&&self.state==1) {
                cell.delegate = self;
                cell.indexPath = indexPath;
                cell.titleLab.text = @"备注";
                if (self.state == 1) {
                    cell.detailTextView.editable = NO;
                    if ([self.detail length]==0) {
                        cell.detailTextView.text = @" ";
                    }else{
                        cell.detailTextView.text= self.detail;
                    }
                }else{
                    cell.detailTextView.editable = YES;
                    cell.detailTextView.placeholder = @"请输入备注内容";
                    cell.detailTextView.text = self.detail;
                }
                return  cell;
            }else{
            SearchForDiseaseAddPicsForIPadCell *cell = [tableView dequeueReusableCellWithIdentifier:PicCellID];
                cell.titleLab.text = @"现场安全措施照片";
                cell.delegate = self;
                if (self.state==1) {
                    cell.isReset = NO;
                }else{
                    cell.isReset = YES;
                }
                cell.con = self;
                [cell addValue:self.imgArray];
            return cell;
            }
        }else if(indexPath.row ==11||indexPath.row==2||indexPath.row==3||indexPath.row==4){
            SearchForDiseaseDetailForIPadCell *cell = [tableView dequeueReusableCellWithIdentifier:DetailCellID];
            cell.titleLab.text = self.titleArray[indexPath.row];
            cell.delegate = self;
            cell.indexPath = indexPath;
            cell.detailTextView.placeholder = self.contentArray[indexPath.row];
            if (self.state == 1) {
                cell.detailTextView.editable = NO;
                if (indexPath.row==11) {
                    if ([self.detail length]==0) {
                        cell.detailTextView.text = @" ";
                    }else{
                        cell.detailTextView.text= self.detail;
                    }
                }
                if (indexPath.row==4) {
                    if ([self.doInfo length]==0) {
                        cell.detailTextView.text = @" ";
                    }else{
                        cell.detailTextView.text= self.doInfo;
                    }
                }
                if (indexPath.row==2) {
                    if ([self.elseThing length]==0) {
                        cell.detailTextView.text = @" ";
                    }else{
                        cell.detailTextView.text= self.elseThing;
                    }
                }
                if (indexPath.row==3) {
                    if ([self.idea length]==0) {
                        cell.detailTextView.text = @" ";
                    }else{
                        cell.detailTextView.text= self.idea;
                    }
                }
                }else{
                cell.detailTextView.editable = YES;
                if (indexPath.row == 2) {
                    cell.detailTextView.text = self.elseThing;
                }else if (indexPath.row == 3){
                    cell.detailTextView.text = self.idea;
                }else if (indexPath.row == 11){
                    cell.detailTextView.text = self.detail;
                }else{
                   cell.detailTextView.text= self.doInfo;
                }
            }

            return cell;
        }else{
            PutNormolForIPadCell *cell = [tableView dequeueReusableCellWithIdentifier:PutCellID];
            cell.titleLab.text = self.titleArray[indexPath.row];
            switch (indexPath.row) {
                case 0:
                    cell.contentLab.text = self.routeName;
                    break;
                case 5:
                    cell.contentLab.text = self.checkerName;
                    break;
                case 6:
                    cell.contentLab.text = self.dic[@"checkDate"];
                    break;
                case 7:
                    cell.contentLab.text = self.safetyUserName;
                    break;
                case 8:
                {
                    
                    cell.contentLab.text = self.checkTime;
                    [cell.titleLab mas_updateConstraints:^(MASConstraintMaker *make) {
                        make.centerY.mas_equalTo(0);
                        make.height.mas_equalTo(36*PadHeightRate);
                        make.left.mas_equalTo(12*PadWidthRate);
                        make.width.mas_equalTo(120*PadWidthRate);
                    }];
                }
                    break;
                case 9:
                    cell.contentLab.text = self.dic[@"inspectionDate"];
                    break;
                default:
                    break;
            }
            if (self.state==1) {
                cell.img.hidden = YES;
            }else{
            if (indexPath.row==5||indexPath.row==7||indexPath.row==8) {
                cell.img.hidden = NO;
                cell.img.image = [UIImage imageNamed:@"enter"];
            }else{
                cell.img.hidden = YES;
            }
            }
            return cell;
        }
    }
    
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([tableView isEqual:self.tableView]) {
        _selectedIndex = indexPath.row;
        self.codeId = self.dataArray[indexPath.row][@"securityCheckId"];
        [self.tableView reloadData];
        
        NSString *str = [NSString stringWithFormat:@"%@",self.dataArray[indexPath.row][@"vcBooleanCode"]];
        if ([str integerValue]) {
            self.state = 1;
        }else{
            self.state = 0;
        }
        [self setWebDataDetail];
        [self normolState:self.state];
    }else{
        if (self.state!=1) {
            if (indexPath.row == 5) {
                [MBProgressHUD showHUDAddedTo:self.rightTableView animated:YES];
                [NetWorkTool receiveManWithUnitID:nil block:^(id data) {
                    [MBProgressHUD hideAllHUDsForView:self.rightTableView animated:NO];
                    if (data) {
                        if([data[@"success"] integerValue]){
                            UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"检查人" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
                            PutNormolForIPadCell *cell = (PutNormolForIPadCell *)[self.rightTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:5 inSection:0]];
                            for (int i = 0; i<[data[@"data"] count]; i++) {
                                [actionSheet addAction:[UIAlertAction actionWithTitle:[NSString stringWithFormat:@"%@",data[@"data"][i][@"userName"]]style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                                    
                                    self.checkerName = data[@"data"][i][@"userName"];
                                    self.checkerId = data[@"data"][i][@"userId"];
                                    cell.contentLab.text = self.checkerName;
                                    
                                }]];
                            }
                          
                            dispatch_async(dispatch_get_main_queue(), ^{
                                actionSheet.popoverPresentationController.sourceView = cell.bgView;
                                actionSheet.popoverPresentationController.sourceRect = CGRectMake(cell.bgView.frame.size.width-15*PadWidthRate,(CGFloat)cell.bgView.frame.size.height/(CGFloat)2.0,1.0,1.0);
                                [self presentViewController:actionSheet animated:YES completion:nil];
                            });
                            
                        }else{
                            
                            [PublicMethod noTokenToLoginWithNav:self.navigationController];
                        }
                        
                    }else{
                        [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"因网络问题获取检查人失败" animated:YES];
                    }
                    
                }];
                
            }
            if (indexPath.row == 7) {
                [MBProgressHUD showHUDAddedTo:self.rightTableView animated:YES];
                [NetWorkTool receiveManWithUnitID:nil block:^(id data) {
                    [MBProgressHUD hideAllHUDsForView:self.rightTableView animated:NO];
                    if (data) {
                        if([data[@"success"] integerValue]){
                            UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"安全管理员" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
                            PutNormolForIPadCell *cell = (PutNormolForIPadCell *)[self.rightTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:7 inSection:0]];
                            for (int i = 0; i<[data[@"data"] count]; i++) {
                                [actionSheet addAction:[UIAlertAction actionWithTitle:[NSString stringWithFormat:@"%@",data[@"data"][i][@"userName"]]style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                                    
                                    self.safetyUserName = data[@"data"][i][@"userName"];
                                    self.safetyUserId = data[@"data"][i][@"userId"];
                                    cell.contentLab.text = self.safetyUserName;
                                    
                                }]];
                            }

                            dispatch_async(dispatch_get_main_queue(), ^{
                                actionSheet.popoverPresentationController.sourceView = cell.bgView;
                                actionSheet.popoverPresentationController.sourceRect = CGRectMake(cell.bgView.frame.size.width-15*PadWidthRate,(CGFloat)cell.bgView.frame.size.height/(CGFloat)2.0,1.0,1.0);
                                [self presentViewController:actionSheet animated:YES completion:nil];
                            });
                            
                        }else{
                            
                            [PublicMethod noTokenToLoginWithNav:self.navigationController];
                        }
                        
                    }else{
                        [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"因网络问题获取安全管理员失败" animated:YES];
                    }
                    
                }];
  
            }
            if (indexPath.row == 8) {
                //x,y 值无效，默认是居中的
                KSDatePicker* picker = [[KSDatePicker alloc] initWithFrame:CGRectMake(0, 0, 280, 260)];
                
                //配置中心，详情见KSDatePikcerApperance
                
                picker.appearance.radius = 5;
                
                //设置回调
                picker.appearance.resultCallBack = ^void(KSDatePicker* datePicker,NSDate* currentDate,KSDatePickerButtonType buttonType){
                    
                    if (buttonType == KSDatePickerButtonCommit) {
                        
                        NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
                        [formatter setDateFormat:@"yyyy-MM-dd"];
                        self.checkTime = [formatter stringFromDate:currentDate];
                        PutNormolForIPadCell *cell = (PutNormolForIPadCell *)[self.rightTableView cellForRowAtIndexPath:indexPath];
                        cell.contentLab.text = self.checkTime;
                    }
                };
                // 显示
                [picker show];
            }
        }

    }
    
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex) {
        [self endPutData];
    }
}
@end
